package com.oocl.servlet;

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.oocl.service.AreasService;
import com.oocl.service.impl.AreasServiceFactory;
import com.oocl.util.RequestUtil;


public class SearchAreasServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		
		Map<String,String> param = RequestUtil.getParameterToString(request);
        String area = param.get("areaName");
		List<String> list = new ArrayList<String>();
		String json = "";
		if(!"".equals(area)){
			AreasService aSer = AreasServiceFactory.createAreasService();
			list = aSer.serchAreasNamesByAreaName(area);
			json = RequestUtil.wrapToJson(list);
			
		}
		System.out.println(json);
		response.setContentType("application/json;charset=utf-8");
		response.getWriter().write(json);
	}

}
